<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>定位居中</title>
    <style>
        div {
            width: 150px;
            height: 150px;
            background-color: #fc8787;


            position: absolute;
            top: 50%;
            left: 50%;

            /* margin方法 */
            /*margin-left: -75px;*/
            /*margin-top: -75px;*/

            /* 推荐transform这种 */
            transform: translate(-50%, -50%);
        }
    </style>
</head>
<body>

<div>

</div>

</body>
</html>